package crudfx.container;
import crudfx.interop.*;
import javax.swing.*;
import java.awt.*;
import crudfx.data.*;
import java.beans.*;
/**
 * @profile desktop
 * @author Sergey Surikov
 */
public class VerticalSplit extends UIComponent {
    var jSplitPane:JSplitPane;
    public var divider:Integer on replace o=n{
        if(not lock){
            jSplitPane.setDividerLocation(divider);
            }
        };
    var lock:Boolean=false;
    public var left:UIComponent on replace o=n{
        if(o!=null)jSplitPane.remove(o.getJComponent());
        jSplitPane.setTopComponent(left.getJComponent());
        };
    public var right:UIComponent on replace o=n{
        if(o!=null)jSplitPane.remove(o.getJComponent());
        jSplitPane.setBottomComponent(right.getJComponent());
        };
    init{
        jSplitPane=new JSplitPane();
        jSplitPane.setOrientation(jSplitPane.HORIZONTAL_SPLIT);
        jSplitPane.setBottomComponent(right.getJComponent());
        jSplitPane.setTopComponent(left.getJComponent());
        jSplitPane.setDividerLocation(divider);
        jSplitPane.setOpaque(false);
        var propertyChangeListener:PropertyChangeListener=PropertyChangeListener{
            override public function propertyChange(evt:PropertyChangeEvent){
                if(evt.getPropertyName().equals(jSplitPane.LAST_DIVIDER_LOCATION_PROPERTY)){
                    lock=true;
                    divider=jSplitPane.getDividerLocation();
                    lock=false;
                    }
                }
            };
        jSplitPane.addPropertyChangeListener(propertyChangeListener);
        }
    override public function getJComponent():JComponent{
        return jSplitPane;
        }
    override public function highlight(s:String):Boolean{
        if(left.highlight(s))return true;
        if(right.highlight(s))return true;
        return false;
        }
    override public function gather():DataTree{
        var me:DataTree=DataTree{ name:"VerticalSplit" };
        insert left.gather() into me.node("left").children;
        insert right.gather() into me.node("right").children;
        return me;
        }
    }
